<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: adminscok.php,v $ 
 * $Date: 2006/03/21 17:52:03 $ 
 * $Revision: 1.5 $ 
 * 
 * ********* CVS HEADER ********* 
 */
$lastid=$argid;
$query="SELECT * from inscription WHERE id='$lastid'";
$result=rportalrequete($query) or die ("ERREUR 0112");
$pwd='';
$row=rportalligne($result);

	//require_once('module/password/password.php');
	require_once(get_path_module("password.password"));
	$pwd = getRandomPassword(8);
	$p=md5($pwd);
	$query="INSERT INTO utilisateur (login,password,nom,prenom,email,id_groupe) VALUES ('$row[login]','$p','$row[nom]','$row[prenom]','$row[email]','".$rportalparams->get_value("RPORTAL","groupe.sequenceur")."')";
	$res=@rportalrequete($query) or die ("ERREUR 0113");
	$argid=rportallastid($res);

$query="SELECT id FROM sequence_ordre WHERE id_sequence='".$rportalparams->get_value("RPORTAL","sequence.inscription")."' ORDER BY id";
$result2=rportalrequete($query) or die ("ERREUR 0114");
$etape=-1;
if($row2=rportalligne($result2))
{
	$etape=$row2[id];
}

$query="INSERT INTO sequence_status (login,id_groupe,etape,id_sequence) VALUES ('$row[login]','$groupe','$etape','".$rportalparams->get_value("RPORTAL","sequence.inscription")."')";
$result=rportalrequete($query) or die ("ERREUR 0115");

$query="DELETE FROM inscription WHERE id='$lastid'";
$result=rportalrequete($query) or die ("ERREUR 0116");


//require_once('module/email/emailtype.php');
require_once(get_path_module("email.emailtype"));
$email = new emailtype($rportalparams->get_value("RPORTAL","email.inscription.accord"));
$email->setFrom($rportalparams->get_value("SITE","webmaster.nom"),$rportalparams->get_value("SITE","webmaster.email"));
$email->setTo($row['email'],$row['login'],$row['nom'],$row['prenom'],$pwd);
	
if(trim($rportalparams->get_value("RPORTAL","email.actif"))=="yes")
{
	$email->sendEmail();
	header("Location: ?op=adminscliste");
}
else
{
	include("environnement/$session[environnement]/header.php");
	require_once(get_path_module("admin"));
	$pc = new panneau_controle();
	$pc->calculRubriqueParFonction('adminscliste');
	echo $pc->retourneEntete();
	echo "EMAIL A ENVOYER:\n";
	echo "<hr/>\n";
	echo "A : ".$row['email']."<br>\n";
	echo "Sujet : ".$email->getTitre()."<br>\n";
	echo "Message :<br>\n";
	echo nl2br($email->getMessage());
	echo "<hr>\n";
	include("environnement/$session[environnement]/footer.php");
}

?>